package funcionarios;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;


public class DataTest {
	private Data data;
	@Before public void SetUP() throws Exception{
		data = new Data("12/11/2010");
	}
	@Test public void testaGet(){
		Assert.assertEquals(12, data.getDia());
		Assert.assertEquals(11, data.getMes());
		Assert.assertEquals(2010, data.getAno());
		Assert.assertEquals("12/11/2010", data.toString());
	}
	@Test public void testaSet() throws Exception{
		data.setDia(1);
		data.setMes(2);
		data.setAno(2020);
		Assert.assertEquals(01, data.getDia());
		Assert.assertEquals(02, data.getMes());
		Assert.assertEquals(2020, data.getAno());
		Assert.assertEquals("1/2/2020", data.toString());
		data.setDia(01);
		data.setMes(02);
		Assert.assertEquals("1/2/2020", data.toString());
		data.setData("15/6/1996");
		Assert.assertEquals("15/6/1996", data.toString());
		try{
			Data data2 = new Data("40/12/2010");
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("A data nao e valida", e.getMessage());
		}
		try{
			data.setAno(1899);
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("Ano deve ser Maior que 1900", e.getMessage());
		}try{
			data.setMes(13);
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("A data nao e valida", e.getMessage());
		}try{
			Data data2 = new Data("1/13/2010");
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("A data nao e valida", e.getMessage());
		}try{
			data.setDia(32);
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("A data nao e valida", e.getMessage());
		}try{
			Data data3 = new Data("29/2/2010");  //Aqui dara erro porque 2010 nao eh ano Bissexto
			Assert.fail();
		}catch(Exception e){
			Assert.assertEquals("A data nao e valida", e.getMessage());
		}
		Data d1 = new Data(" 15/6/1996");
		Assert.assertEquals(true, data.equals(d1));


		
		
	}
}
